from langgraph.graph import START,END, StateGraph
from langgraph.prebuilt import ToolNode
from langchain_community.tools import TavilySearchResults

def my_node(state):
    return {"x":state["x"] + 1, "y":state["y"] + 1}

def my_node1(state):
    return {}
def my_node2(state):
    return {}
stat = StateGraph(dict)
search = TavilySearchResults(max_results=2)
# print(search.invoke("成都今天天气怎样？"))
#模型绑定工具
tools = [search]
tool_node = ToolNode(tools)
stat.add_node(my_node)
stat.add_node(tool_node)
stat.add_edge(START, "my_node")

stat.add_edge("my_node", "tools")
stat.add_edge("tools", END)
graph = stat.compile()
graph_png = graph.get_graph().draw_mermaid_png()
with open("graph.png", "wb") as f:
    f.write(graph_png)
#下载图片
print(graph)